const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const webpack = require('webpack');
// const BundleAnalyzerPlugin = require('webpack-bundle-analyzer')
//   .BundleAnalyzerPlugin;

module.exports = {
  mode: 'none',
  stats: 'verbose',
  entry: {
    index: './src/index.js'
    // another: './src/another-module.js'
  },
  plugins: [
    // 打包前 清理out文件夹
    new CleanWebpackPlugin(['dist']),
    // 重新生成index.html
    new HtmlWebpackPlugin({
      title: 'tree shaking'
    })
    // new webpack.NamedModulesPlugin(),
    // new webpack.HotModuleReplacementPlugin(),
    // new webpack.optimize.CommonsChunkPlugin({
    //   name: 'common' // 指定公共 bundle 的名称。
    // })，
    // new Visualizer({filename: './statics.html'}),
    // new BundleAnalyzerPlugin(),
  ],
  output: {
    filename: '[name].bundle.js',
    chunkFilename: '[name].bundle.js',
    path: path.resolve(__dirname, 'dist')
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: ['style-loader', 'css-loader']
      },
      {
        test: /\.(png|svg|jpg|gif)$/,
        use: ['file-loader']
      },
      {
        test: /\.(woff|woff2|eot|ttf|otf)$/,
        use: ['file-loader']
      }
    ]
  },
  optimization: {
    splitChunks: {
      chunks: 'all'
    }
  },
  recordsPath: path.resolve(__dirname, 'records.json'),
  recordsInputPath: path.resolve(__dirname, 'records.json'),
  recordsOutputPath: path.resolve(__dirname, 'records.json')
};
